home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #11 / Amiga Plus CD - 2002 - No. 11.iso / Tools / Development / libogg / libvorbis-1.0rc3 / lib / analysis.c next >
Encoding:
C/C++ Source or Header  |  2002-10-27  |  3.2 KB  |  117 lines

  1. /********************************************************************
  2.  *                                                                  *
  3.  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
  4.  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
  5.  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
  6.  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
  7.  *                                                                  *
  8.  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001             *
  9.  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
  10.  *                                                                  *
  11.  ********************************************************************
  12.  
  13.  function: single-block PCM analysis mode dispatch
  14.  last mod: $Id: analysis.c,v 1.47 2001/12/12 09:45:24 xiphmont Exp $
  15.  
  16.  ********************************************************************/
  17.  
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include <math.h>
  21. #include <ogg/ogg.h>
  22. #include "vorbis/codec.h"
  23. #include "codec_internal.h"
  24. #include "registry.h"
  25. #include "scales.h"
  26. #include "os.h"
  27.  
  28. int analysis_noisy=1;
  29.  
  30. /* decides between modes, dispatches to the appropriate mapping. */
  31. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  32.   vorbis_dsp_state     *vd=vb->vd;
  33.   backend_lookup_state *b=vd->backend_state;
  34.   vorbis_info          *vi=vd->vi;
  35.   codec_setup_info     *ci=vi->codec_setup;
  36.   int                   type,ret;
  37.   int                   mode=0;
  38.  
  39.   vb->glue_bits=0;
  40.   vb->time_bits=0;
  41.   vb->floor_bits=0;
  42.   vb->res_bits=0;
  43.  
  44.   /* first things first.  Make sure encode is ready */
  45.   oggpack_reset(&vb->opb);
  46.   /* Encode the packet type */
  47.   oggpack_write(&vb->opb,0,1);
  48.   
  49.   /* currently lazy.  Short block dispatches to 0, long to 1. */
  50.   
  51.   if(vb->W &&ci->modes>1)mode=1;
  52.   type=ci->map_type[ci->mode_param[mode]->mapping];
  53.   vb->mode=mode;
  54.  
  55.   /* Encode frame mode, pre,post windowsize, then dispatch */
  56.   oggpack_write(&vb->opb,mode,b->modebits);
  57.   if(vb->W){
  58.     oggpack_write(&vb->opb,vb->lW,1);
  59.     oggpack_write(&vb->opb,vb->nW,1);
  60.     /*fprintf(stderr,"*");
  61.   }else{
  62.   fprintf(stderr,".");*/
  63.   }
  64.  
  65.   if((ret=_mapping_P[type]->forward(vb,b->mode[mode])))
  66.     return(ret);
  67.  
  68.   if(op){
  69.     op->packet=oggpack_get_buffer(&vb->opb);
  70.     op->bytes=oggpack_bytes(&vb->opb);
  71.     op->b_o_s=0;
  72.     op->e_o_s=vb->eofflag;
  73.     op->granulepos=vb->granulepos;
  74.     op->packetno=vb->sequence; /* for sake of completeness */
  75.   }
  76.   return(0);
  77. }
  78.  
  79. /* there was no great place to put this.... */
  80. void _analysis_output_always(char *base,int i,float *v,int n,int bark,int dB){
  81.   int j;
  82.   FILE *of;
  83.   char buffer[80];
  84.  
  85.   /*  if(i==5870){*/
  86.     sprintf(buffer,"%s_%d.m",base,i);
  87.     of=fopen(buffer,"w");
  88.     
  89.     if(!of)perror("failed to open data dump file");
  90.     
  91.     for(j=0;j<n;j++){
  92.       if(dB && v[j]==0)
  93.     fprintf(of,"\n\n");
  94.       else{
  95.     if(bark)
  96.       fprintf(of,"%g ",toBARK(22050.f*j/n));
  97.     else
  98.       fprintf(of,"%g ",(double)j);
  99.     
  100.     if(dB){
  101.       fprintf(of,"%g\n",todB(v+j));
  102.     }else{
  103.       fprintf(of,"%g\n",v[j]);
  104.     }
  105.       }
  106.     }
  107.     fclose(of);
  108.     /*  } */
  109. }
  110.  
  111. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB){
  112. #ifdef ANALYSIS
  113.   if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB);
  114. #endif
  115. }
  116.  
  117.